package com.dev.bbs.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.dev.bbs.domain.BbsConfig;
import com.dev.bbs.mapper.BbsConfigMapper;
import com.dev.bbs.service.IBbsConfigService;
import com.dev.common.constant.ConfigKeyConstants;
import com.dev.common.exception.BusinessException;
import com.dev.common.utils.RedisUtils;

/**
 * bbs参数配置Service业务层处理
 * 
 * @author dev
 * @date 2019-09-30
 */
@Service
public class BbsConfigServiceImpl implements IBbsConfigService 
{
    @Autowired
    private BbsConfigMapper bbsConfigMapper;

    /**
     * 查询bbs参数配置
     * 
     * @param key bbs参数配置key
     * @return bbs参数配置
     */
    public BbsConfig selectBbsConfigByKey(String key)
    {
        BbsConfig bbsConfig = new BbsConfig();
        Object object = RedisUtils.get(ConfigKeyConstants.FORGOT_MAIL);
        if(object == null){
            bbsConfig = bbsConfigMapper.selectOne(new BbsConfig().setConfigKey(ConfigKeyConstants.FORGOT_MAIL));
            if(bbsConfig == null){
                throw new BusinessException("配置为空");
            }
            RedisUtils.set(ConfigKeyConstants.FORGOT_MAIL,bbsConfig);
        }else {
            bbsConfig = JSONObject.parseObject(String.valueOf(object),BbsConfig.class);
        }
        return bbsConfig;
    }

}
